package bill.study.concurrency.javacip.chapter5.futuretask;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Preloader {
	
	private final FutureTask<ProductInfo> future=
		new FutureTask<ProductInfo> (new Callable<ProductInfo>(){
			public ProductInfo call(){
				return loadProductInfo();
			}
		});
	
	private final Thread thread = new Thread(future);
	
	public void start(){
		thread.start();
	}

	public ProductInfo get() throws DataLoadException, InterruptedException{

		try{
			return future.get();
		}catch (ExecutionException ee){
			Throwable cause = ee.getCause();
			if(cause instanceof DataLoadException){
				throw new DataLoadException();
			}
			else{
				//launderThrowable(cause);
			}
		}
		return null;
		
	}
	
	public ProductInfo loadProductInfo(){
		return null;
		
	}
}
